package com.teach.servlet.admin;


import com.teach.dao.MedalInfoDAO;
import com.teach.dao.impl.MedalInfoDAOImpl;
import com.teach.entity.MedalInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * -
 * 当前的项目名：medal-2022
 *
 * @author ZT
 * @data 2022/5/8 22:10
 **/
@WebServlet("/admin/medal-update.let")
public class MedalUpdateServlet extends HttpServlet {
    private MedalInfoDAO dao = new MedalInfoDAOImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.reset();
        response.setContentType("application/json;charset=UTF-8");
        try {
            MedalInfo e = new MedalInfo();

           e.setMedalId(Integer.valueOf(request.getParameter("medalId")));
           e.setSeId(Integer.valueOf(request.getParameter("seId")));
           e.setSportsmanId(Integer.valueOf(request.getParameter("sportsmanId")));
           e.setMedalNum(Integer.valueOf(request.getParameter("medalNum")));
           e.setMedalResult(request.getParameter("medalResult"));
            SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
            Date d = sd.parse(request.getParameter("medalDate"));
            e.setMedalDate(d);

            try {
                dao.updateById(e);
                response.getWriter().print("{\"ok\":true}");
            } catch (Exception ex) {

            }

        }catch (Exception ex){
            response.getWriter().print("{\"ok\":false,\"msg\":\""+ex.getMessage()+"\"}");
        }

        response.flushBuffer();
    }
}
